﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

public partial class KMrpt8 : ExtBaseRpt
{
    string mid;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            BuildGridPanel(this.GridPanel1, mid, Session["UserID"].ToString());
            this.txtstatus.GetStore().DataSource = db.DM_GetDateSet("select stateid,cnstatename as statename from Sys_State where statefixflag='auditresult'");
            txtvendor.GetStore().DataSource = db.DM_GetDateSet("select vendcustid,vendcustname from Bas_InterCompany order by vendcustname");
            this.txtseason.GetStore().DataSource = mydb.DM_GetDateSet("select distinct seasonname from v_mat");
            this.txtyear.GetStore().DataSource = mydb.DM_GetDateSet("select distinct yearno from v_mat order by yearno");
            this.txtmatkind.GetStore().DataSource = mydb.DM_GetDateSet("select distinct kindname from v_mat");
            this.txtbdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            this.txtedate.Text = DateTime.Now.ToString();
            //this.txtbjhdate.Text = DateTime.Now.ToString("yyyy-MM-01");
            //this.txtejhdate.Text = DateTime.Now.ToString();
        }
    }
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        string bdate,edate,sjhdaate, ejhdaate, sdhdate,edhdate,srkdate,erkdate;
        if (Convert.ToDateTime(txtbdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            bdate = "";
        else
            bdate = txtbdate.Text;

        if (Convert.ToDateTime(txtedate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edate = "";
        else
            edate = txtedate.Text;

        if (Convert.ToDateTime(txtbjhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            sjhdaate = "";
        else
            sjhdaate = txtbjhdate.Text;

        if (Convert.ToDateTime(txtejhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            ejhdaate = "";
        else
            ejhdaate = txtejhdate.Text;
        if (Convert.ToDateTime(txtsdhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            sdhdate = "";
        else
            sdhdate = txtsdhdate.Text;
        if (Convert.ToDateTime(txtedhdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            edhdate = "";
        else
            edhdate = txtedhdate.Text;
        if (Convert.ToDateTime(txtsrkdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            srkdate = "";
        else
            srkdate = txtsrkdate.Text;
        if (Convert.ToDateTime(txterkdate.Text) == Convert.ToDateTime("0001-01-01 00:00:00"))
            erkdate = "";
        else
            erkdate = txterkdate.Text;
        string status = StrSplitParam(txtstatus);
        string season = StrSplitParam(this.txtseason);
        string yearno = StrSplitParam(this.txtyear);
        string matkind = StrSplitParam(this.txtmatkind);
        this.Store1.DataSource = db.DM_GetDateSet("exec KM_PurSituation_Rpt '" + bdate + "','" + edate
            + "','" + sjhdaate + "','" + ejhdaate + "','" + sdhdate + "','" + edhdate + "','" + srkdate
            + "','" + erkdate + "','" + status + "','" + txtvendor.Value + "','" + season
            + "','" + yearno + "','" + matkind + "','" + txtmatname.Text + "',0");
        this.Store1.DataBind();
    }


    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid,"xls",e.Xml,this.Response,this.Title);
    }
}